Skip to content

build: upgrade TypeScript to 7.0 - #56

Merged
yCodeTech merged 10 commits into
masterfrom
build/upgrade-typescript
Sep 6, 2026
Merged

build: upgrade TypeScript to 7.0#56
yCodeTech merged 10 commits into
masterfrom
build/upgrade-typescript

Conversation

@yCodeTech

@yCodeTech yCodeTech commented Aug 25, 2026

Copy link
Copy Markdown
Owner

This pull request upgrades the TypeScript dependency to 7.0 and includes several improvements and refactorings aimed at increasing code safety, robustness, and maintainability, as well as fixing the new TS errors. The most notable changes are stricter null checks, improved type assertions, and the refactoring of the logger.

Dependency Updates:

  • Upgraded the typescript dependency to version ^7.0.0 in package.json.

TS Error Fixing:

  • Added nullish coalescing and optional chaining throughout src/configuration.ts to prevent runtime errors from undefined or null values (e.g., when reading JSON files, accessing properties, or merging arrays).

  • Improved type assertions and handling of possibly undefined variables, especially in methods dealing with editor actions and configuration retrieval.

  • Improved null safety and early returns in src/extensionData.ts when reading and setting extension metadata, ensuring the extension does not attempt to use undefined package data.

  • Refactored the logger in src/logger.ts, moving output channel initialisation into the constructor and removing the need for a separate setup method.

@yCodeTech
yCodeTech force-pushed the build/upgrade-typescript branch from 97ece2a to 617d329 Compare August 26, 2026 06:34
Base automatically changed from build/dependency-version-bumps to master September 5, 2026 05:01
From Node v6, you have to explicitly include type modules, otherwise they will not be added globally to the project like `process` for Node, and module imports will error like `Cannot find name 'node:fs'`.

- Added `types` array to tsconfig and included the `node` and `vscode` modules to fix import and usage errors.

Ref: http://typescriptlang.org/tsconfig/#types
Fixed TS 7.0 errors by ensuring:

- Variables don't have `undefined` or `null` values before accessing them and providing fallback values if they are undefined with the null coalescing operator (??) and conditional ternary operator (? .. : .. ).

- Values from methods are satisfying their expected return types using the `as` keyword and generic typed method calls.

- Object keys aren't accessed if the object itself is `undefined` with the optional chaining operator (?.) and proper undefined type guards and conditionals.

- `reconstructRegex` util function infers the correct type from the passed `obj` param.

- Error stack logging has a fallback of the error message in case the stack is null/undefined.

- `convertMapToReversedObject` util function has properly typed `result` instead of implicit `any` type and changed the reverse object mapping to mutate the existing array instead of rebuilding a new one on every iteration.
- Changed type of `packageJsonData` property to allow it to be `null`.

- Moved the null check from the `constructor` to the `setExtensionData` method, and use the check to narrow the type and assert that it's not null/falsy, and return early if it is. Using a local variable instead of accessing the property directly ensures TS doesn't keep spitting out null possibility errors.
@yCodeTech
yCodeTech force-pushed the build/upgrade-typescript branch from dc82707 to 3c36b06 Compare September 5, 2026 06:12
…uctor.

- Fixed the TS error "Property 'outputChannel' has no initializer and is not definitely assigned in the constructor." in Logger by adding a `constructor` and initialise the output channel inside it.
- Removed the now redundant `setupOutputChannel` Logger method and it's references, this is because the output channel is now setup in the `constructor` so we have no need for this method now.

- Removed the redundant `outputChannel` property null check in `showChannel` method since it's never null as it's initialised in `constructor`.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Two moderate type-contract and error-fallback issues remain unresolved.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Upgrades the extension to TypeScript 7 and adapts types, nullability, and initialization behavior for compatibility.

Changes:

  • Updates TypeScript and ECMAScript targets.
  • Strengthens nullability, collection, and error-handling types.
  • Initializes the singleton logger eagerly.
File summaries
File Description
tsconfig.json Targets ES2025 and declares required types.
src/utils.ts Tightens utility types; unmapped filesystem errors need the UNKNOWN fallback.
src/logger.ts Initializes the output channel in the constructor.
src/extensionData.ts Handles nullable package metadata.
src/extension.ts Removes redundant logger setup.
src/configuration.ts Adds nullability safeguards, but incorrectly makes the required editor edit optional.
package.json Upgrades TypeScript to 7.0.
Review details
  • Files reviewed: 6/7 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/configuration.ts Outdated
Comment thread src/utils.ts
- Reverted the `edit` param in the `handleSingleLineBlock` Configuration method back to be required instead of optional because it otherwise insinuates the method can work without the `edit` param which is not true. It must have the param set to work. Also removed the optional chaining operator on the `edit.insert` call. The TS error that the optional operators fixed will return:

"Type '(textEditor: TextEditor, edit: TextEditorEdit) => void' is not assignable to type '(textEditor: TextEditor, edit?: TextEditorEdit | undefined) => void'.
  Types of parameters 'edit' and 'edit' are incompatible.
    Type 'TextEditorEdit | undefined' is not assignable to type 'TextEditorEdit'.
      Type 'undefined' is not assignable to type 'TextEditorEdit'."

- Fixed the returning TS error above by making the `edit` param required instead of optional in the `handler` function in `CommandRegistration` interface, which the `handleSingleLineBlock` method has to satisfy.
If an error code was caught but isn't listed in the messages map, then the `errorMsg` in `validateDevEnvVariables` utils function would return something like "ENOTDIR: undefined: ...".

- Fixed by adding a fallback to the `UKNOWN` entry when an error code is not mapped.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

All reviewed changes are safe, and no unresolved issues remain.

Review details
  • Files reviewed: 7/8 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@yCodeTech
yCodeTech merged commit 1529d5d into master Sep 6, 2026
2 checks passed
@yCodeTech
yCodeTech deleted the build/upgrade-typescript branch September 6, 2026 23:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants